package com.example.demo;

import org.apache.commons.lang3.StringUtils;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2016</p>
 * <p>Company: Sunshine Insurance Group Co., Ltd.</p>
 *
 * @author lbb
 * @version 1.0
 * 修改记录：
 * 修改序号，修改日期，修改人，修改内容
 */
public class JdkProxyFactory implements InvocationHandler {

    private Object target;

    public JdkProxyFactory(Object object) {
        this.target = object;
    }


    public Object getProxyInstance(){

        return Proxy.newProxyInstance(this.target.getClass().getClassLoader(),this.target.getClass().getInterfaces(),this);
    }



        @Override
        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
            System.out.println("JDK代理");
            Object result = method.invoke(this.target, args);
            if(result != null && result instanceof String) {
                result = StringUtils.isBlank((String) result) ? null : result;
            }
            System.out.println("JDK代理");
            return result;
        }

}
